package com.bing.jh.controller;

import com.bing.bingPro.common.BaseResult;
import com.bing.bingPro.util.ExcelData;
import com.bing.bingPro.util.WebExcelUtil;
import com.bing.jh.entity.dto.TZwArchivesDto;
import com.bing.jh.entity.vo.DzWzCostMatchDtlVO;
import com.bing.jh.entity.vo.DzWzCostMatchStatVO;
import com.bing.jh.entity.vo.DzWzUserGroupStatVO;
import com.bing.jh.service.DzWzCostMatchStatService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * 装维人员与成本随销数据匹配-统计数据
 */
@RestController
@RequestMapping("dzWzCostMatchStat")
public class DzWzCostMatchStatController {

    @Resource
    private DzWzCostMatchStatService dzWzCostMatchStatService;
    @PostMapping("/list")
    public BaseResult<List<DzWzCostMatchStatVO>> list(@RequestBody TZwArchivesDto tZwArchives) {
        //return new BaseResult<>(dzWzCostMatchStatService.list(tZwArchives));
        return new BaseResult<>(dzWzCostMatchStatService.queryAll(tZwArchives));
    }

    @PostMapping("/dateList")
    public BaseResult<List<String>> dateList() {
        return new BaseResult<>(dzWzCostMatchStatService.dateList());
    }

    @PostMapping("/exportAll")
    public void exportAll(HttpServletResponse response, @RequestBody TZwArchivesDto tZwArchives) throws Exception {
        List<DzWzCostMatchStatVO> list = dzWzCostMatchStatService.queryAll(tZwArchives);
        //整理查询的数据
        List<ExcelData> excelDataList = new ArrayList<>();
        ExcelData excelData = new ExcelData(DzWzCostMatchStatVO.class,
                list);
        excelDataList.add(excelData);
        //写出到浏览器
        WebExcelUtil.download(response, "统计数据" + tZwArchives.getMonth() + "全国+31省+所有地市", excelDataList);
    }
}
